﻿using RuoVea.Entity;
using Mapster;
using SqlSugar;
using RuoVea.Autowired;
using RuoVea.ExSqlSugar;
using Microsoft.AspNetCore.Mvc;
using RuoVea.Service;

namespace RuoVea.Api.Controllers
{
    /// <summary>
    /// 角色服务
    /// </summary>
    public class SysRoleController : ApiBaseController
    {
        private readonly ISysRoleService _sysRoleService; 
        private readonly ISysRoleMenuService _sysRoleMenuService;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sysRoleService"></param>
        /// <param name="sysRoleMenuService"></param>
        public SysRoleController(ISysRoleService sysRoleService,ISysRoleMenuService sysRoleMenuService)
        {
            _sysRoleService = sysRoleService;
            _sysRoleMenuService = sysRoleMenuService;
        }

        /// <summary>
        /// 分页获取角色列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("page")]
        public async Task<dynamic> QueryRolePageList([FromQuery] RoleInput input)
        {
            return await _sysRoleService.QueryRolePageList(input);
        }

        /// <summary>
        /// 角色下拉（用于授权角色时选择）
        /// </summary>
        /// <returns></returns>
        [HttpGet("dropDown")]
        public async Task<dynamic> GetRoleDropDown()
        {
            return await _sysRoleService.GetRoleDropDown( );
        }

        /// <summary>
        /// 增加角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("add")]
        public async Task AddRole(AddRoleInput input)
        {
            await _sysRoleService.AddRole(input);
        }

        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("delete")]
        public async Task DeleteRole(DeleteRoleInput input)
        {
            await _sysRoleService.DeleteRole(input);
        }

        /// <summary>
        /// 更新角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("edit")]
        public async Task UpdateRole(UpdateRoleInput input)
        {
            await  _sysRoleService.UpdateRole(input);
        }

        /// <summary>
        /// 获取角色
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("detail")]
        public async Task<SysRole> GetRoleInfo([FromQuery] QueryRoleInput input)
        {
            return await _sysRoleService.GetRoleInfo(input);
        }

        /// <summary>
        /// 授权角色菜单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("grantMenu")]
        public async Task GrantMenu(GrantRoleMenuInput input)
        {
            await _sysRoleService.GrantMenu(input);
        }

        /// <summary>
        /// 获取角色拥有菜单Id集合
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpGet("ownMenu")]
        public async Task<List<long>> OwnMenu([FromQuery] QueryRoleInput input)
        {
            return await _sysRoleMenuService.GetRoleMenuIdList(new List<long> { input.Id });
        }
    }
}
